﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Reflection;

namespace newTurtle8
{
    public partial class SoldiersView : Form
    {
        public enum Type {All, NotCalled, Called} 
        DataTable dt;
        Mofa mofa;
        Type type;
        MethodInfo methodInfo;
        
        public SoldiersView(Mofa mofa,SoldiersView.Type type, Delegate d)
        {
            InitializeComponent();
            this.mofa = mofa;
            SqlCommand sqlCmd = new SqlCommand();
            this.type = type;
            methodInfo = d.Method;

            switch (type)
            {
               /* case Type.All:
                    break;*/
                case Type.NotCalled:
                    //retreive all not-called-soldiers table.
                     sqlCmd = SqlManager.getSqlCommandFromFile(@"\SELECT\NotCalledSoldiers.SELECT.sql");
                    break;
                case Type.Called:
                    //retreive all already-called-soldiers table.
                    sqlCmd = SqlManager.getSqlCommandFromFile(@"\SELECT\AlreadyCalledSoldiers.SELECT.sql");
                    sqlCmd.CommandText = sqlCmd.CommandText.Replace("Table", mofa.ZimunimTableName);
                    sqlCmd.Parameters.Add("@startDate", SqlDbType.Date).Value = mofa.StartDate;
                    break;
              /*  default:
                    break;*/
            }
          
            dt = SqlManager.selectSqlQueryDataTable(sqlCmd);
            dataGridView.DataSource = dt;
            Translator.setTableColumnHeadersHebrew(dataGridView.Columns);
        }

        private void buttonAdd_Click(object sender, EventArgs e)
        {
            List<string> addList = new List<string>();
            foreach (DataGridViewRow row in dataGridView.SelectedRows)
                addList.Add((string)row.Cells["armyID"].Value);

            methodInfo.Invoke(mofa, new object[] { addList });
            this.Dispose();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
            this.Dispose();
        }
    }
}

